package com.woniu.job.service.impl;

import com.woniu.job.entity.Category;
import com.woniu.job.mapper.CategoryMapper;
import com.woniu.job.mapper.FavoriteMapper;
import com.woniu.job.mapper.WorkMapper;
import com.woniu.job.service.ICategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.job.util.Helper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 *   状态：1正常     2 已删除
 *
 * </p>
 *
 * @author song
 * @since 2019-12-24
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements ICategoryService {




    @Resource
    CategoryMapper categoryMapper;

    @Override
    public List<Category> getAll() {

        Map<String,Object > map=new HashMap<>();
        map.put("status","1");

       return categoryMapper.selectByMap(map);

    }


    @Override
    public Category add(Category category) {
        category.setId(Helper.getId());
        category.setStatus("1");
        categoryMapper.insert(category);
        return  category;
    }

    @Override
    public Category getById(String id) {

        return categoryMapper.selectById(id);
    }

    @Override
    public void realDel(String id) {

         categoryMapper.deleteById(id);
    }

    @Override
    public void del(String id) {

        Category category=new Category();
        category.setId(id);
        category.setStatus("2");
        categoryMapper.updateById(category);
    }

    @Override
    public void update(Category category) {
        categoryMapper.updateById(category);
    }

    @Override
    public List<Category> selectByParent(String id) {

        Map<String,Object > map=new HashMap<>();
        map.put("parentId",id);
        map.put("status","1");
        return categoryMapper.selectByMap(map);
    }


}
